<template>
  <div class="title-bar drag">
    <div class="title-wrap">
      <div class="avatar">
        <img :src="defaultAvatar" alt="">
      </div>
      <p class="title">{{ store.title }}</p>
    </div>
    <div class="controls">
      <button class="btn min" @click="minimize">－</button>
      <button class="btn max" @click="maximize">□</button>
      <button class="btn close" @click="close">×</button>
    </div>
  </div>
</template>

<script setup>
  import defaultAvatar from '@/assets/image/default-avatar.jpg'
  import { useTitleStore } from '@/store'

  const minimize = () => window.api.minimize();
  const maximize = () => window.api.maximize();
  const close = () => window.api.close();

  const store = useTitleStore()
</script>

<style lang="scss" scoped>
.title-bar {
  width: 100%;
  height: 35px;
  background: #2f3241;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 12px;
  color: var(--color-text-2);

  &.drag {
    -webkit-app-region: drag; /* 允许拖拽窗口 */
  }
  &.no-drag {
    -webkit-app-region: no-drag; /* 禁止按钮被拖拽 */
  }

  .title-wrap {
    display: flex;
    align-items: center;

    .avatar {
      width: 26px;
      height: 26px;
      border-radius: 50%;
      overflow: hidden;
      display: flex;
      justify-content: center;
      align-items: center;

      img {
        width: 100%;
      }
    }

    .title {
      margin-left: 6px;
    }
  }

  .controls .btn {
    width: 22px;
    height: 22px;
    -webkit-app-region: no-drag;
    margin-left: 12px;
    border-radius: 3px;
    font-size: 16px;
    text-align: center;
    line-height: 22px;
    color: var(--color-text-2);
    box-shadow: 0 0 8px 4px rgba(255, 255, 255, .12);
    cursor: pointer;

    &.min {
      background-color: #FF3B30;
    }

    &.max {
      background-color: #FF9500;
    }

    &.close {
      background-color: #4CD964;
    }
  }
}
</style>